﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace Game1942.Library.Controller
{
    public class SaveUnit : IXmlSerializable
    {
        public int energy;
        public int amountOfRockets;
        public int amountOfTorpedos;
        public int score;
        public int lifes;
        public int xPos;
        public int yPos;

        public XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(XmlReader reader)
        {
            reader.MoveToContent();
            energy = int.Parse(reader.GetAttribute("energy"));
            amountOfRockets = int.Parse(reader.GetAttribute("amountOfRockets"));
            amountOfTorpedos = int.Parse(reader.GetAttribute("amountOfTorpedos"));
            score = int.Parse(reader.GetAttribute("score"));
            lifes = int.Parse(reader.GetAttribute("lifes"));
            xPos = int.Parse(reader.GetAttribute("xPos"));
            yPos = int.Parse(reader.GetAttribute("yPos"));
        }

        public void WriteXml(XmlWriter writer)
        {
            writer.WriteAttributeString("energy", Driver.Instance.Player.Energy.ToString());
            writer.WriteAttributeString("amountOfRockets", Driver.Instance.Player.AmountOfRockets.ToString());
            writer.WriteAttributeString("amountOfTorpedos", Driver.Instance.Player.AmountOfTorpedos.ToString());
            writer.WriteAttributeString("score",Driver.Instance.Score.ToString());
            writer.WriteAttributeString("lifes", Driver.Instance.Player.Lifes.ToString());
            writer.WriteAttributeString("xPos", Driver.Instance.Player.ActualPosition.X.ToString());
            writer.WriteAttributeString("yPos", Driver.Instance.Player.ActualPosition.Y.ToString());
        }
    }
}
